package com.core.base.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.core.base.searchForm.ISearchForm;
import com.core.base.searchForm.hql.IBaseHQLSearchForm;
import com.core.base.searchForm.support.SearchFormCommonDao;
import com.core.page.PagerResult;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 基础action，所有的action继承此类,主要对基本信息的封装和继承struts2类
 * @author pt-chenqw
 * @param <T>
 *
 */
@SuppressWarnings({"rawtypes","unchecked"})
public abstract class BaseAction extends ActionSupport implements RequestAware,SessionAware,ModelDriven{

	private static final long serialVersionUID = 1L;
	
	@Resource(name="searchFormCommonDAO")
	private SearchFormCommonDao searchFormCommonDao;
	
	public Map<String,Object> request;
	
	public Map<String,Object> session;

	@Override
	public void setSession(Map<String, Object> session) {
		
		this.session = session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		
		this.request = request;
	}
	
	public <T> PagerResult<T> findBySearchForm(Class<T> searchClass,ISearchForm searchForm){
		return searchFormCommonDao.findbyCondition(searchClass, searchForm);
	}
	
	public <T> PagerResult<T> findByHQLSearchForm(Class<T> searchClass,IBaseHQLSearchForm searchForm){
		return searchFormCommonDao.findbyHQLCondition(searchClass, searchForm);
	}
	
	

}
